<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<title></title>
<jsp:include page="../links.jsp"></jsp:include>
</head>
<body>
	<script type="text/javascript">
		var admin_datagrid;
		var admin_searchForm;
		var admin_addDlg;
		var admin_addForm;
		var admin_updateDlg;
		var admin_updateForm;
		$(function() {
			admin_datagrid = $('#admin_datagrid').datagrid({
				url : getRootPath() + '/admin/adminAction/datagrid.do',
				title : '用户列表',
				iconCls : 'icon-admin',
				pagination : true,
				rownumbers : true,
				selectOnCheck : true,
				checkOnSelect : false,
				pageSize : 10,
				pageList : [ 10, 20, 30, 40, 50 ],
				fit : true,
				fitColumns : true,
				nowarp : false,
				border : false,
				idField : 'id',
				sortOrder : 'asc',
				columns : [ [ {
					title : '',
					field : '0',
					width : 100,
					checkbox : true
				}, {
					title : '编号',
					field : 'id',
					width : 100,
					sortable : false
				}, {
					title : '管理员名',
					field : 'name',
					width : 100,
				}, {
					title : '密码',
					field : 'pwd',
					width : 200,
				} ] ],
				toolbar : [ {
					text : '添加',
					iconCls : 'icon-add',
					handler : function() {
						admin_showAddDlg();
					}
				}, '-', {
					text : '修改',
					iconCls : 'icon-edit',
					handler : function() {
						admin_showUpdateDlg();
					}
				}, '-', {
					text : '删除',
					iconCls : 'icon-remove',
					handler : function() {
						admin_remove();
					}
				} ]
			});//datagrid end
			//过滤查询
			admin_searchForm = $('#admin_searchForm').form();
			admin_doSearch = function() {
				//console.info(serializeObject(admin_searchForm));
				admin_datagrid.datagrid('load', serializeObject(admin_searchForm));
			};
			//重置
			admin_cleanSearch = function() {
				admin_datagrid.datagrid('load', {});
				admin_searchForm.find('input').val('');
			};
			//新增
			admin_addDlg = $('#admin_addDlg').dialog();
			admin_addForm = $('#admin_addForm').form();
			admin_showAddDlg = function() {
				$('#admin_addForm input').val('');
				admin_addDlg.dialog('open')
			};
			admin_doAdd = function() {
				admin_addForm.form('submit', {
					url : '${pageContext.request.contextPath}/admin/adminAction/add.do?',
					onSubmit : function() {
						if ($('#apwd3').val() == $('#apwd4').val()) {
							return true;
						} else {
							$.messager.alert('提示', '两次密码输入不一致');
							$('#apwd3').val('');
							$('#apwd4').val('');
							return false;
						}
					},
					success : function(data) {
						var r = $.parseJSON(data);
						if (r && r.success) {
							admin_addDlg.dialog('close');
							admin_cleanSearch();
							$.messager.show({
								title : '提示',
								msg : r.msg,
								showType : 'show'
							});
						} else {
							$.messager.alert('提示', r.msg);
						}
					}
				});
			};
			//修改
			admin_updateDlg = $('#admin_updateDlg').dialog();
			admin_updateForm = $('#admin_updateForm').form();
			admin_showUpdateDlg = function() {
				var selectids = admin_datagrid.datagrid('getChecked');
				if (selectids.length == 1) {
					admin_updateDlg.dialog('open');
					$('#admin_up_id').val(selectids[0].id);
					$('#admin_up_name').val(selectids[0].name);
				} else {
					$.messager.alert('提示', "请勾选一项");
				}
			};
			admin_doUpdate = function() {
				admin_updateForm.form('submit', {
					url : '${pageContext.request.contextPath}/admin/adminAction/update.do?',
					success : function(data) {
						var r = $.parseJSON(data);
						if (r && r.success) {
							admin_updateDlg.dialog('close');
							admin_cleanSearch();
							$.messager.show({
								title : '提示',
								msg : r.msg,
								showType : 'show'
							});
						} else {
							$.messager.alert('提示', r.msg);
						}
					}
				});
			};
			//删除
			admin_remove = function() {
				var selectids = admin_datagrid.datagrid('getChecked');
				var ids = [];
				if (selectids.length > 0) {
					$.messager.confirm('确认', '您是否要删除当前选中的项目？', function(r) {
						if (r) {
							for (var i = 0; i < selectids.length; i++) {
								ids.push(selectids[i].id);
							}
							$.ajax({
								url : '${pageContext.request.contextPath}/admin/adminAction/delete.do',
								data : {
									ids : ids.join(',')
								},
								dataType : 'json',
								success : function(r) {
									admin_datagrid.datagrid('load');
									admin_datagrid.datagrid('unselectAll');
									$.messager.show({
										title : '提示',
										msg : r.msg
									});
								}
							});
						}
					});
				} else {
					$.messager.alert('提示', "请最少勾选一项");
				}
			};
		});
	</script>
	<div class="easyui-layout" data-options="fit:true,border:false">
		<div data-options="region:'north',title:'模糊查询条件：(右边可折叠)'" style="height: 100%;">
			<form id="admin_searchForm" method="post">
				<table style="width: 100%; height: 60%;">
					<tr>
						<th></th>
						<td></td>
					</tr>
					<tr>
						<th class="th-search-label">编号:</th>
						<td><input name="admin.id" maxLength=11 class="easyui-numberbox" type="text" /></td>
						<th class="th-search-label">管理员名:</th>
						<td><input name="admin.name" /></td>
						<td><a class="easyui-linkbutton" style="width: 25%" data-options="iconCls:'icon-search'"
							href="javascript:void(0)" onclick="admin_doSearch();">查询</a>&nbsp;<a class="easyui-linkbutton"
							style="width: 25%" data-options="iconCls:'icon-redo'" href="javascript:void(0)"
							onclick="admin_cleanSearch();">清空</a></td>
					</tr>
				</table>
			</form>
		</div>
		<div data-options="region:'center',title:''," style="overflow: hidden;">
			<table id="admin_datagrid">
			</table>
		</div>
		<div id="admin_addDlg"
			data-options="closed:true,modal:true,title:'添加用户',buttons:[
				{text : '添加',iconCls : 'icon-add',handler : function() {admin_doAdd();}},
				{text : '取消',iconCls : 'icon-cancel',handler : function() {admin_addDlg.dialog('close');}}]"
			class="easyui-dialog" style="width: 270px; height: 160px;" align="center">
			<form id="admin_addForm" method="post">
				<table>
					<tr>
						<th>管理员名:</th>
						<td><input name="admin.name" class="easyui-validatebox" data-options="required:true" /></td>
					</tr>
					<tr>
						<th>密码:</th>
						<td><input id="apwd3" name="admin.pwd" type="password" class="easyui-validatebox"
							data-options="required:true" /></td>
					</tr>
					<tr>
						<th>确认密码:</th>
						<td><input id="apwd4" name="admin.rpwd" type="password" class="easyui-validatebox"
							data-options="required:true" /></td>
					</tr>
				</table>
			</form>
		</div>
		<div id="admin_updateDlg"
			data-options="closed:true,modal:true,title:'修改用户',buttons:[
				{text : '修改',iconCls : 'icon-save',handler : function() {admin_doUpdate();}},
				{text : '取消',iconCls : 'icon-cancel',handler : function() {admin_updateDlg.dialog('close');}}]"
			class="easyui-dialog" style="width: 270px; height: 180px;" align="center">
			<form id="admin_updateForm" method="post">
				<table>
					<tr>
						<th>编号:</th>
						<td><input id="admin_up_id" name="admin.id" class="easyui-validatebox" data-options="required:true"
							readonly="readonly" /></td>
					</tr>
					<tr>
						<th>管理员名:</th>
						<td><input id="admin_up_name"  name="admin.name" class="easyui-validatebox" data-options="required:true" /></td>
					</tr>
					<tr>
						<th>密码:</th>
						<td><input name="admin.pwd" type="password" class="easyui-validatebox"
							data-options="required:true" /></td>
					</tr>
				</table>
			</form>
		</div>
	</div>
</body>
</html>